package com.aiwu.memory;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.aiwu.BaseLazyFragment;
import com.aiwu.library.App;

import org.citra.citra_emu.R;

/**
 * 搜索结果太多的页面
 */
public class MemoryResultManyFragment extends BaseLazyFragment {
    private static final String TAG = MemoryResultManyFragment.class.getName();
    private TextView tvNum, tvTip, tvOk;

    @Override
    protected void lazyLoad() {
        int resultSize = MemoryManager.getInstance().getMemorySize();
        if (resultSize > MemoryManager.RESULT_NUM_THRESHOLD) {
            String numStr = "共搜索到" + resultSize + "个数值";
            SpannableString ssNum = new SpannableString(numStr);
            int start = 4;
            int end = numStr.indexOf("个数值");
            ssNum.setSpan(new ForegroundColorSpan(ContextCompat.getColor(App.getContext(), R.color.text_imp)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvNum.setText(ssNum);

            switch (MemoryManager.getInstance().getSearchType()) {
                default:
                case MemoryManager.SEARCH_TYPE_NORMAL:
                    String tipStr = "请返回游戏使数值" + MemoryManager.getInstance().getLastSearchValue() + "发生变化，然后激活作弊器输入变化后的值进一步搜索";
                    SpannableString ssTip = new SpannableString(tipStr);
                    int start2 = 8;
                    int end2 = tipStr.indexOf("发生变化");
                    ssTip.setSpan(new ForegroundColorSpan(ContextCompat.getColor(App.getContext(), R.color.text_imp)), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    tvTip.setText(ssTip);
                    break;
                case MemoryManager.SEARCH_TYPE_FUZZY:
                    tvTip.setText("请返回游戏使数值发生变化，然后激活作弊器输入变化后的值进一步搜索");
                    break;
            }
        }
    }

    @Override
    protected Boolean repeatedLoad() {
        return true;
    }

    @Override
    protected int initContentView() {
        return R.layout.fragment_memory_result_many;
    }

    @Override
    protected void initView(View view) {
        tvNum = view.findViewById(R.id.tv_num);
        tvTip = view.findViewById(R.id.tv_tip);
        tvOk = view.findViewById(R.id.tv_ok);
        tvOk.setOnClickListener(v -> {
            MemoryManager.getInstance().backGame();
        });
    }

}
